package android.slc.user.ui.dept.fragment

import android.os.Bundle
import android.slc.appbase.ui.fragment.base.AppMvvmBaseFragment
import android.slc.user.R
import android.slc.user.databinding.UserFragmentDeptListBinding
import android.slc.user.ui.dept.delegate.DeptListBrowserDelegate
import android.slc.user.ui.dept.vm.DeptListBrowseVm
import android.slc.user.ui.dept.vmbox.DeptListBrowseVmBox
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.ToastUtils

/**
 *
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/12/06 下午 3:24
 *
 */
class DeptListBrowserFragment :
    AppMvvmBaseFragment<UserFragmentDeptListBinding, DeptListBrowseVm>() {
    override fun setContentView(): Any {
        return R.layout.user_fragment_dept_list
    }

    override fun onBindView(savedInstanceState: Bundle?) {
        super.onBindView(savedInstanceState)
        DeptListBrowserDelegate().apply {
            init(
                this@DeptListBrowserFragment, dataBinding.root,
                viewModel.dataListVmBox as DeptListBrowseVmBox
            )
        }
    }

    override fun onRegisterLiveEvent() {
        super.onRegisterLiveEvent()
        viewModel.dataListVmBox.showTreeClickUiOf.observe(this, object : Observer<Bundle> {
            override fun onChanged(value: Bundle) {
                /*start(DeptListBrowserFragment().apply {
                    arguments = value
                })*/
                ToastUtils.showShort("改变了架构，这里请完善")
            }
        })
    }

    override fun onBindViewLater() {
        super.onBindViewLater()
        arguments?.let {
            viewModel.initVm(it)
        } ?: let {
            ToastUtils.showShort(R.string.user_label_dept_not_found)
            requireActivity().finish()
        }
    }
}